<template>
  <div id="app">
    <el-form :model="document" label-width="100px">
      <el-form-item label="文档名">
        <el-input v-model="document.name"></el-input>
      </el-form-item>

      <el-form-item label="附件" prop="gender">
        <el-upload
          class="upload-demo"
          action="http://localhost:8989/document/uploadAttach"
          :limit="1"
          :on-exceed="handleOnExceed"
          name="attach"
          accept=".pdf"
          :multiple="false"
          :on-success="handleOnSuccess"
        >
          <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">只能上传pdf文件</div>
        </el-upload>
      </el-form-item>

      <el-form-item label="描述">
        <el-input v-model="document.description"  type="textarea" rows="5"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click.prevent="test">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    data(){
      return {
        document:{
          name:""
        }
      }
    },
    methods:{
      test(){
            //发出保存请求
            this.$confirm("是否确认提交","保存提示").then(()=>{
              this.axios.post("/document/add",this.document).then((resp)=>{
                this.$message.success("保存成功！");
                this.$router.push("/document/DocumentList")
              });
            });
      },
      handleOnExceed(){
        console.log("文件个数超出限制");
      },
      handleOnSuccess(resp){
        //文件上传成功之后要把文件上传到哪传给brand对象
        this.document.attachment=resp;
      },
    }
  }
</script>


<style scoped>

</style>
